﻿using System;
using System.Collections.Generic;
using System.Data;
using Hotel.Classes.Helper;
using Hotel.Models.Entity;

namespace Hotel.Models.DataAccess
{
    public class DAFloor
    {
        //GetList : floorID = 0
        //GetDetail : floorID = ID
        public static List<Floor> GetListFloor(int floorID)
        {
            DataTable dt;
            List<Floor> listFloor = new List<Floor>();
            using (DBManager dbManager = new DBManager("stp_Get_Floors"))
            {
                dbManager.Add("p_PK_FloorID", floorID);
                dbManager.Add("IsDelete", 0);
                dt = dbManager.GetDatatable();
            }
            foreach (DataRow dr in dt.Rows)
            {
                Floor floor = new Floor();
                floor.PkFloorId = DataHelper.GetInt(dr, "PK_FloorID");
                floor.Name = DataHelper.Get(dr, "Name");
                listFloor.Add(floor);
            }
            return listFloor;
        }
       
        public static bool DeleteFloor(int floorID)
        {
            using (DBManager dbManager = new DBManager("stp_Get_Floors"))
            {
                try
                {
                    dbManager.Add("p_PK_FloorID", floorID);
                    dbManager.Add("IsDelete", 1);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                
            }
        }

        //Insert : isUpdate = false
        //Update : isUpdate = true
        public static bool SaveFloor(Floor floor, bool isUpdate)
        {
            using (DBManager dbManager = new DBManager("stp_Create_Floors"))
            {
                try
                {
                    dbManager.Add("p_PK_FloorID", floor.PkFloorId);
                    dbManager.Add("p_Name", floor.Name);
                    dbManager.Add("IsUpdate", isUpdate);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {

                    return false;
                }
                
            }
        }
    }
}